package com.xzqwjw.taskmanager.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.leaderinfo.model.InfoContact;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class ContactDao implements com.leaderinfo.service.OperateDatabaseService {

	private SQLiteDatabase objDB;
	private String strDBFile = "";

	public ContactDao(String strDBFile) {
		this.strDBFile = strDBFile;
	}

	@Override
	public Map<String, Object> getRecordByAID(int intAID) {
		return null;
	}

	@Override
	public Map<String, Object> getRecordByBasicID(int intBasicID) {
		InfoContact objContactInfo = null;
		Map<String, Object> mapInfo = null;

		objDB = SQLiteDatabase.openOrCreateDatabase(strDBFile, null);

		String strSQL = "SELECT * FROM info_cadre_contact WHERE id_basic=?";
		String[] aryArgs = { String.valueOf(intBasicID) };

		Cursor objCursor = objDB.rawQuery(strSQL, aryArgs);
		if (objCursor.moveToFirst()) {
			objContactInfo = new InfoContact();
			getInfo(objCursor, objContactInfo);
			mapInfo = new HashMap<String, Object>();
			mapInfo.put("ContactInfo", objContactInfo);
		}
		objCursor.close();
		objDB.close();
		return mapInfo;
	}

	@Override
	public List<Map<String, Object>> getRecordsByBasicID(int intBasicID) {
		return null;
	}

	@Override
	public List<Map<String, Object>> getAllRecords() {
		return null;
	}

	private void getInfo(Cursor objCursor, InfoContact objContactInfo) {
		objContactInfo.AID = objCursor.getInt(objCursor.getColumnIndex("aid"));
		objContactInfo.BasicID = objCursor.getInt(objCursor
				.getColumnIndex("id_basic"));
		objContactInfo.AddressWork = objCursor.getString(objCursor
				.getColumnIndex("address_work"));
		objContactInfo.AddressHome = objCursor.getString(objCursor
				.getColumnIndex("address_home"));
		objContactInfo.PhoneWork = objCursor.getString(objCursor
				.getColumnIndex("phone_work"));
		objContactInfo.PhoneMobile = objCursor.getString(objCursor
				.getColumnIndex("phone_mobile"));
		objContactInfo.PhoneHome = objCursor.getString(objCursor
				.getColumnIndex("phone_home"));
		objContactInfo.PhoneSecretary = objCursor.getString(objCursor
				.getColumnIndex("phone_secretary"));
		objContactInfo.Email = objCursor.getString(objCursor
				.getColumnIndex("email"));
		objContactInfo.Zipcode = objCursor.getString(objCursor
				.getColumnIndex("zipcode"));
	}

	@Override
	public List<Map<String, Object>> getRecordsByWhere(String strWhere) {
		return null;
	}

}
